package com.panghl.repository;

import com.panghl.entity.Article;
import org.hibernate.annotations.OnDelete;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @Author panghl
 * @Date 2022/2/18
 **/
@Repository
public interface ArticleDao extends JpaRepository<Article, Integer>, JpaSpecificationExecutor<Article>, CrudRepository<Article,Integer> {

    Article findByCategory(String category);

    //@Query("select u from Article as u where u.category like %?1% ")
    @Query("select u from Article as u where u.category like %:category% ")
    Page<Article> findByCategoryLikeAndSort(@Param("category") String category, Pageable pageable);

}
